package com.example.yuejian21.nongfusanquan.yuejian21.activity;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;

import com.example.yuejian21.nongfusanquan.yuejian21.R;
import com.example.yuejian21.nongfusanquan.yuejian21.adapter.UsercollectAdapter;
import com.example.yuejian21.nongfusanquan.yuejian21.javabean.UserCollectclubbean;
import com.example.yuejian21.nongfusanquan.yuejian21.model.Clubmodel;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Nongfusanquan on 2017-11-13.
 */

public class MycollectclubActivity extends AppCompatActivity {

        private Button back_collect;
        private RecyclerView recyclerView;
        private View view=null;
        private int u_id;

        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_mycollect);
            initViews();
            initEvent();
            getData();
        }
        private void initViews(){
            back_collect = (Button)findViewById(R.id.return_collect);
            recyclerView=(RecyclerView)findViewById(R.id.rv);
            recyclerView.setLayoutManager(new LinearLayoutManager(this));//设置布局
        }

        private void initEvent(){
            back_collect.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    finish();
                }
            });
        }

    private void getData() {
        SharedPreferences sp =this.getSharedPreferences("cache", Context.MODE_APPEND);
        u_id = Integer.parseInt(sp.getString("uid","0"));

        Clubmodel Model=new Clubmodel();
        Call<List<UserCollectclubbean>> call=Model.getMyCollectlist(u_id);
        call.enqueue(new Callback<List<UserCollectclubbean>>() {
            @Override
            public void onResponse(Call<List<UserCollectclubbean>> call, Response<List<UserCollectclubbean>> response) {
                List<UserCollectclubbean> data = response.body();  //获取数据
                recyclerView.setAdapter(new UsercollectAdapter(MycollectclubActivity.this, data));
            }

            @Override
            public void onFailure(Call<List<UserCollectclubbean>> call, Throwable t) {

            }
        });

    }
}
